package algorithm.test;

public class Shell {
    public static void insertPro(Comparable[] a){
        int h=1;
        int l=a.length;
        while (h<l/2){
            h=h*2+1;
        }

        do{
            for (int i=h;i<l;i++){
                for (int j=i;j>=h;j=j-h){
                    if (greater(a[j-h],a[j])){
                        exch(a,j-h,j);
                    }else {
                        break;
                    }
                }

            }
            if (h==1){
                break;
            }
            h=h/2;
        }while (true);

    }
    public static boolean greater(Comparable v,Comparable w){
        return v.compareTo(w)>0;
        //v是否大于w
    }

    private static void exch(Comparable[] a,int i,int j){
        Comparable t=a[i];
        a[i]=a[j];
        a[j]=t;
    }
}
